package org.dawning.shop.common.domain.cart;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.axonframework.common.Assert;
import org.axonframework.common.IdentifierFactory;
import org.dawning.shop.common.domain.product.ProductId;

/**
 * Created by miou on 2017/6/13 0013.
 */
@Data
@AllArgsConstructor
public class CartId {

    private final String identifier;
    private final int hashCode;


    /**
     *  使用用户id作为聚合跟
     * @param userId
     */
    public CartId(String userId) {
        Assert.notNull(userId, ()->"Identifier may not be null");
        this.identifier = userId;
        this.hashCode = identifier.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ProductId)) return false;

        CartId cartId = (CartId) o;

        return identifier.equals(cartId.identifier);
    }

    @Override
    public int hashCode() {
        return identifier.hashCode();
    }
}
